let fs = require('fs')
const dayjs = require('dayjs')

const getPackageJson = () => {
    let data = fs.readFileSync('./package.json') //fs读取文件
    return JSON.parse(data.toString()) //转换为json对象
}
let packageData = getPackageJson()
const changeBuildTime = () => {
    packageData.lastBuildTime = dayjs().unix()
        // dayjs().format('YYYY-MM-DD HH:mm:ss')
}
changeBuildTime()
fs.writeFile('./package.json', JSON.stringify(packageData, null, '\t'), err => {
    if (err) {
        console.log('写入失败', err)
    } else {
        console.log('构建时间写入成功 ' + packageData.lastBuildTime)
    }
})
